// pages/detail-songs/index.js
import  {rankingStore} from '../../store/index'
import {getSongMenuDetail} from '../../service/api_music' 
import {playerStore} from '../../store/payer-store'
Page({
  data: {
    type:'',
    ranking:'',
    songInfo:{},

  },
  onLoad:function(options){
    const type=options.type
    this.setData({type})
    // console.log(options);
    if(type=='menu'){
      const id=options.id
      getSongMenuDetail(id).then(res=>{
        this.setData({songInfo:res.playlist})
      })
    }else if(type=='rank'){
      const ranking=options.ranking
      this.setData({ranking})
      // 获取数据
      rankingStore.onState(ranking,this.getRankingDataHanler)
    }

  },
  getRankingDataHanler:function(res){

    this.setData({songInfo:res})
      //  console.log(res);
  },
  handleSongItemClick:function(e){
    const index=e.currentTarget.dataset.index
    console.log(index,this.data.songInfo);
    playerStore.setState('playListSongs',this.data.songInfo.tracks)
    playerStore.setState('playListIndex',index)

  }
})